<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\api\controller;

use app\api\model\Help as HelpModel;
use app\api\model\Order as OrderModel;
use app\api\model\wxapp\Setting as WxappSettingModel;
use app\common\library\helper;
use app\common\library\wechat\WxUser;
use app\common\service\bangdou\BdPay as BdPayService;
use app\common\service\bangdou\Common as CommonService;
use app\common\service\XinLian\OpenApi as OpenApiService;
use app\models\bangdou\BdPay;
use app\common\library\wechat\WxSendGood;
use app\common\service\wxpush\WXBizMsgCrypt;
use cores\exception\BaseException;
use app\api\model\OrderGoods as OrderGoodsModel;
use app\common\model\OrderSub as OrderSubModel;
use app\common\library\wechat\WxApi;

use app\common\service\fulu\FuLu as FuLu;
use think\facade\Queue;


/**
 * 帮助中心
 * Class help
 * @package app\store\controller\wxapp
 */
class Test extends Controller
{
    /**
     * 获取列表记录
     * @return array
     * @throws \think\db\exception\DbException
     */
    public function test()
    {
        /*$pay_data['recharge_account'] = '13971210120';
        $pay_data['user_id'] = '72';
        $pay_data['order_id'] = '706';
        $pay_data['order_no'] = '202407130914100525';
        $pay_data['goods_no'] = 'G32811953973924836';
        $aa = BdPayService::OrderXinLianPayment($pay_data);
        var_dump($aa);exit;*/
        /*$aa = [
            'business_name'=>'邦诺众益',
            'business_address'=>'武汉市江汉区',
            'business_tel'=>'15254213878',
            'contacts_name'=>'张女士',
            'contacts_tel'=>'15412469498',
            'email'=>'qwqww@163.com',
            'legal_name'=>'张珊',
            'legal_card'=>'142222456697994456',
            'license_code'=>'123123124534535',
            'license_range'=>'丝绸、布匹',
            'license_add'=>'武汉市江汉区香港路',
            'license_date'=>'2024-01-01',
            'license_start_time'=>'2024-01-01',
            'license_end_time'=>'2029-01-01',
            'legal_card_img'=>'12',
            'license_img'=>'19',
            'business_category'=>["10006","10007"],
            'bank_name'=>'招商银行',
            'bank_account'=>'张三',
            'sub_branch'=>'招商银行武汉关谷支行',
            'bank_card'=>'622544668434115566874',
            'permit_img'=>'65'
        ];
        $bb =['from'=>$aa];
        var_dump(json_encode($bb));exit;*/
        $params['out_trade_no']   = "202406130457971029";
        $params['transaction_id'] = "4200002126202402295802691154";
        $params['tmpOutTardeNo']  = "1202402290222069047_58";
        $params['timestamp']      = time();
        $sign                     = CommonService::getBangDouApisign($params);

        $params['sign'] = $sign;
        $url            = 'http://devaa.bangnuo.top/index.php?s=/api/PayNotice/bangnuoNotice&sign=' . $sign;
        $result         = helper::httpPost($params, $url);
        var_dump($result);
    }

    public function refund()
    {
        $orderInfo['order_id']  = '2';
        $orderInfo['pay_price'] = '1.01';
        $transaction_id         = '4200002109202401313240040349';
        echo BdPayService::bangdouRefund($orderInfo, $transaction_id, null);//三券退款
    }

    public function goods()
    {
        $transaction_id = '4200002096202401311616996395';
        $aa             = WxappSettingModel::getWxappConfig(10001);
        $WxSendGood     = new WxSendGood($aa);
        echo $WxSendGood->getWxSendOrderStatus($transaction_id);//三券退款
    }

    public function send()
    {
        $order['transaction_id']  = '4200002322202407051663375358';
        $order['title']           = '什湖 核心产区五常大米 五常稻花香5kg';
        $order['openid']          = 'ouv_E6yAbkQAvMY8tvDLJ-joe7HM';
        $order['mobile']          = '15210229198';
        $order['tracking_no']     = '9875693896745';
        $order['express_company'] = 'yzguonei';
        $order['order_parent_id'] = '632';
        $order['user_id'] = 16;
        $aa                       = WxappSettingModel::getWxappConfig(10001);
        $WxSendGood               = new WxSendGood($aa);
        $aa                       = $WxSendGood->sendWechatOrder($order);//三券退款
        var_dump($aa);
    }

    public function crypt()
    {
        $token          = 'bq5xbsqLV3D948Sbgq2ii0ll';
        $encodingAesKey = "tLwyJxvspISuJBGMC6saaOb045zhxs9HXZYu5GgzRkQ";
        $timeStamp      = "1708414222";
        $nonce          = "1312635554";
        $appId          = "ouv_E6wBYnan-tMpdC34TAwoqwmc";
        $xmlString      = '<xml>
    <ToUserName><![CDATA[gh_0ed1f1fff94b]]></ToUserName>
    <FromUserName><![CDATA[ouv_E6wBYnan-tMpdC34TAwoqwmc]]></FromUserName>
    <CreateTime>1708414222</CreateTime>
    <MsgType><![CDATA[event]]></MsgType>
    <Event><![CDATA[trade_manage_order_settlement]]></Event>
    <transaction_id><![CDATA[4200002115202402046706277968]]></transaction_id>
    <merchant_id><![CDATA[1648693000]]></merchant_id>
    <sub_merchant_id><![CDATA[0]]></sub_merchant_id>
    <merchant_trade_no><![CDATA[1202402040243961159_28]]></merchant_trade_no>
    <pay_time>1707035810</pay_time>
    <shipped_time>1708410162</shipped_time>
    <confirm_receive_method>1</confirm_receive_method>
    <confirm_receive_time>1708414220</confirm_receive_time>
    <settlement_time>1708414222</settlement_time>
    <Encrypt><![CDATA[/gOBiUUVtikvcnueNkBY3jUwxI+VnfOeYyjO7ICF20oFPlJbIto7eGG9qpjxTtBvR7ktu2Z6DahIgy4uQY0bMocsXVeaN+amRVVte8NpnRO74nAhJYvWAZXXaIUcSMRQJLEC5zVP7uMa//3Lp85DStUgI8juOxjICSKDpgpp6ybG/06JfV08BFyJH3hg4TSxgVdGghwF5vFakHs/Ot9ooxov/Sbsu/TrR4pUdyG1UsiHUS0TtW0gwNftS04ExM4eg7UTxbY9jmVozdt2ANBiLIhoQ2p5aHgrglyIiBPobNERsnm71herBFw8PvOcAWkYzCs7VbIEZD2xKY9PGLUY646iirNpr9cjsaYigC9gqOxKm09bds49Qfchvby/SOslst/U9h7CYfeFCfLXeUfdrOwUQvnpEDE8XWfBNIttpIiLYNOLuwgrPU9m1PH6iZu+6CUmg5kqzcZlPVkY9oypWLB1N48UP7XfK3C2rCbpsi6ScbErOk1nA+sWU98hbUSSJlyqGrYwkmQ9hLEhJCG6rlsctJp/GQg97EJ1qJbYk7JXr0LehqJTUutryd/723+6T5fe5rSO5WLsW3t6XTTQPnFyOK95RpRFOS1itjuCyAVM/PR5oTHoslhnRT1SY/Dx2jYLU48J2uWkoAhy4HIzkQSB3AumTSWaQBkSMfqfW/G37KZ4yKtHNpbheLATSO6J0WB0aTfVRmfTjkUpKcZXAC3kVCSlnw+vKkBmv/Zis9OMddSwMPBUhHw0M70M7fwAt8WTjeMP3ULwMYYnbFUstrg9xUOOKOlZeUQk8wgo7l0t1MhfAkYGZv0I2Cl7d/3vmDcn+pVz1XRb20sbowhOH3tXxJGcCCaKsNkoSZe0sX1rXy+0QDX11Gqf2Oye6xyUr+IJKscD1YobsO9hphdrPUetWirTTxG4COroIXQmOSa4rulQAG0c1iMx/1koOEd3b7KfYCkBt3VARJvP+IOyjquS7FlZfw+1sgJuM2FR1iDcd7Fk9h7+dUYCz79/u82hklu5EtqmRQo4pp4SZI4hXUwR+fmv3xJmFCFmB+fX9ak=]]></Encrypt>
</xml>';

        $data = simplexml_load_string($xmlString, 'SimpleXMLElement', LIBXML_NOCDATA);

        var_dump($data);
        exit;
    }


    /**
     * 心链虚拟商品购买回调
     * @return array
     * @throws \think\db\exception\DbException
     */
    public function xinlian()
    {
        $params = [
            'order_no' => 'OD48589909447328672',
            'merchant_no' => '202406190523984810',
            'recharge_account' => '15210229198',
            'recharge_status' => '4',
            'complete_time' => '2024-05-10 11:28:48',
            'settlement_price' => '18.20',
            'total_amount' => '30.00',
            'actual_amount' => '30.00',
            'create_time' => '2024-05-10 11:26:31',
            'custom_tag' =>'',
            'sign' => '2ce2c387147a57792b2c2f1f6b09357a',
        ];

        $url            = 'https://shopdev.bangnuo.top/index.php?s=/api/PayNotice/xinLianNotice';
        $result         = helper::httpPost($params, $url);
        var_dump($result);
    }

    /**
     * 获取列表记录
     * @return array
     * @throws \think\db\exception\DbException
     */
    public function wxpay()
    {
        $params['appid'] = 'wx1d96411a48d34b4c';
        $params['attach'] = '{"order_type":10}';
        $params['bank_type'] = 'CIB_DEBIT';
        $params['cash_fee'] = '7';
        $params['fee_type'] = 'CNY';
        $params['is_subscribe'] = 'N';
        $params['mch_id'] = '1670400983';
        $params['nonce_str'] = 'cdf28171e2f37d9074f7d117057f4200';
        $params['openid'] = 'ouv_E6xU3Epo_B_zhKi06Du04BE0-joe7HM';
        $params['out_trade_no'] = '202406130457971029_7557';
        $params['result_code'] = 'SUCCESS';
        $params['return_code'] = 'SUCCESS';
        $params['sign'] = 'AF79C2712857D47F8F41B62ACD6AB34B';
        $params['time_end'] = '20240523134907';
        $params['total_fee'] = '7';
        $params['trade_type'] = 'JSAPI';
        $params['transaction_id'] = '4200002211202405319205558347';
        $url = 'http://devaa.bangnuo.top/index.php?s=/api/notify/wxpay&sign=' . $params['sign'];
        //$url            = 'http://devaa.bangnuo.top/index.php?s=/api/PayNotice/bangnuoNotice&sign=' . $sign;
        $result         = helper::httpPost($params, $url);
        var_dump($result);
    }

    public function wxcode()
    {
        // 获取当前小程序信息
        //$wxConfig = static::getMpWxConfig();
        $wxConfig['app_id'] = 'wx1d96411a48d34b4c';
        $wxConfig['app_secret'] = '4f5d412a46636b228808d1a430176938';
        // 微信登录 (获取session_key)
        $WxApi = new WxApi($wxConfig['app_id'], $wxConfig['app_secret']);
        $code='bangdou';
        $result = $WxApi->WxCode($code);

    }

    public function testQueue()
    {

        // 队列名称
        //$queueName = 'test';

        // 队列的数据
        $data = [
            'id'     => 1,
            'name'   => '张三',
            'gender' => '男',
            'type'   => 1
        ];

        // 队列处理类
        $queueClass = \app\queue\TestQueue::class;

        $res = Queue::push($queueClass, $data);
        dump($res);

        exit;
    }
}
